package item

import (
	"project-info/src/handle/jenkins"
	"project-info/src/router/req"
	"project-info/src/router/variable"

	"github.com/gin-gonic/gin"
)

func init() {
	variable.InitRouteFunc = append(variable.InitRouteFunc, InitItemRoutes)
}

func InitItemRoutes(e *gin.Engine) {
	itemGroup := req.NewGroup("/item").NeedToken().SetUpGroup(e)

	reqs := []*req.Conf{
		req.NewPost("/add", jenkins.AddItem),
		req.NewPost("/delete", jenkins.DelItem),
		req.NewGet("/manage/tree", jenkins.GetItemManageTree),
		req.NewGet("/tree", jenkins.GetItemTreeWithPermission).WithMiddleware(req.DataPermissionHandlerConfig()),
	}
	req.BatchSetUpRouter(itemGroup, reqs)

	flowControlGroup := e.Group("/flowControl")
	reqs = []*req.Conf{
		req.NewPost("/update", jenkins.UpdateFlowControl),
		req.NewGet("/get", jenkins.GetFlowControl),
	}
	req.BatchSetUpRouter(flowControlGroup, reqs)

	itemVersionGroup := e.Group("/itemVersion")
	reqs = []*req.Conf{
		req.NewPost("/add", jenkins.AddItemVersion),
		req.NewPost("/delete", jenkins.DeleteItemVersion),
		req.NewGet("/list", jenkins.GetItemVersionList),
	}
	req.BatchSetUpRouter(itemVersionGroup, reqs)
}
